package com.saguitech.sgemeos.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.widget.Toast;

import com.saguitech.sgemeos.R;

public class IsNetworkAvailable extends AsyncTask<Context, Void, Boolean> {

	Context context;
	
	@Override
	protected Boolean doInBackground(Context... params) {
		context = params[0];
		ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		boolean isWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
		boolean is3g = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
		return isWifi || is3g;
	}

	@Override
	protected void onPostExecute(Boolean isAvailable) {
		if(!isAvailable){
			Toast.makeText(context, R.string.serverErrorMsg,
					Toast.LENGTH_SHORT).show();
		}
	}

}
